var vm = new Vue({
    el: '#app',
    data: {
        list: '',
    },
    methods:{
        getSelect(){
            $.ajax({
                url: "aclModule/getSelect",
                type: "post",
                success: function (res) {

                    for (var i=0; i<res.length; i++){
                        $("#selectSM").append("<option value='"+ res[i].id +"'>"+res[i].name+"</option>");

                        $("#addSelectAcl").append("<option value='"+ res[i].id +"'>"+res[i].name+"</option>");
                    }
                }
            });

        },
        getAcl(){

            $.ajax({
                url: 'acl/queryAcl',
                success: function (res) {

                    vm.list = res.list;

                    //bootstrap 分页
                    var options = {
                        bootstrapMajorVersion: 3,
                        currentPage: res.page,
                        totalPages: res.totalPage,
                        size: "normal",
                        alignment: "center",
                        itemTexts:function(type,page, current){
                            switch (type) {
                                case "first":
                                    return "首页";
                                case "prev":
                                    return "上一页";
                                case "next":
                                    return "下一页";
                                case "last":
                                    return "尾页";
                                case "page":
                                    return page;
                            }
                        },
                        onPageClicked: function (event, originalEvent, type, page) {

                            $.ajax({
                                url:'acl/queryAcl', //点击分页提交当前页码
                                data:{
                                    page: page
                                },
                                success:function(data){
                                    vm.list = data.list;
                                }
                            })
                        }
                    };

                    $("#page").bootstrapPaginator(options);
                }
            });
        }
    },
    filters:{
        typeFormat: function (str) {
            if (str == 1){
                return "菜单";
            } else if (str == 2) {
                return "按钮";
            } else {
                return "其他";
            }
        },
        statusFormat: function (str) {
            if (str == 1) {
                return "有效";
            }else {
                return "冻结";
            }
        }
    },
    created(){
        this.getSelect();
        this.getAcl();
    }
});

// bootstrap 模态框 权限模块添加
$('#addAclModuleForm').on('show.bs.modal', function (event) {

    // 添加提交
    $('#add_acl_module_submit').on('click', function(){

        var parentId = $("#selectSM option:selected").val();
        var isParent = $("#isParent option:selected").val();
        var status = $("#status option:selected").val();
        var name = $('#addAclModuleName').val();
        var seq = $('#addSeq').val();
        var remark = $('#addRemark').val();


        $.ajax({
            url: 'aclModule/saveAclModule',
            dataType:'json',
            type:'POST',
            data: {
                parent_id: parentId,
                is_parent: isParent,
                status: status,
                name: name,
                seq: seq,
                remark: remark
            },
            success: function(data){

            }
        });

        $('#addAclModuleForm').modal('hide');
    });

});

// bootstrap 模态框 权限点添加
$('#addAclForm').on('show.bs.modal', function (event) {

    // 添加提交
    $('#add_acl_submit').on('click', function(){

        var acl_module_id = $("#addSelectAcl option:selected").val();
        var parentId = $("#addParentId option:selected").val();
        var type = $("#addType option:selected").val();
        var status = $("#addAclStatus option:selected").val();
        var name = $('#addAclName').val();
        var url = $('#addURL').val();
        var seq = $('#addAclSeq').val();
        var remark = $('#addAclRemark').val();


        $.ajax({
            url: 'acl/saveAcl',
            dataType:'json',
            type:'POST',
            data: {
                acl_module_id: acl_module_id,
                type: type,
                status: status,
                name: name,
                url: url,
                seq: seq,
                remark: remark,
                parent_id: parentId
            },
            success: function(data){

            }
        });

        $('#addAclForm').modal('hide');
    });

});